﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace Yeap.Kernel.Storage
{
    public class UserRepository : RepositoryBase<User>, IUserRepository
    {
        public User ReadByCredentials(string login, string password)
        {
            try
            {
                return Query(u => u.Login == login && u.Password == password).FirstOrDefault();
            }
            catch(Exception )
            {
                if (context.Connection.State == ConnectionState.Broken)
                {
                    context.Connection.Close();
                }
                if (context.Connection.State == ConnectionState.Closed)
                {
                    context.Connection.Open();
                }
                return Query(u => u.Login == login && u.Password == password).FirstOrDefault();
            }
        }

        public User ReadByLogin(string login)
        {
            return Query(u => u.Login.Equals(login)).FirstOrDefault();
        }

    }
}